package com.sky.controller.admin;

import com.sky.constant.RedisConstant;
import com.sky.result.Result;
import com.sky.service.RedisService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author moningxi
 */
@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Api(tags = "店铺相关接口")
@Slf4j
public class ShopController {
    @Resource
    private RedisService redisService;

    @PutMapping("/{status}")
    @ApiOperation("设置营业状态")
    public Result editStatus(@PathVariable int status) {
        log.info("设置营业状态:{}", status);
        redisService.saveString(RedisConstant.SHOP_BUSINESS_STATUS, status);
        return Result.success();
    }

    @GetMapping("/status")
    @ApiOperation("获取营业状态")
    public Result<Integer> getStatus() {
        Integer status = (Integer) redisService.getString(RedisConstant.SHOP_BUSINESS_STATUS);
        return Result.success(status);
    }
}
